package com.gxa.modules.community.controller;


import com.gxa.modules.community.entity.AnnouncementList;
import com.gxa.modules.community.entity.CommunityAnnouncement;
import com.gxa.modules.community.service.CommunityAnnouncementService;
import com.gxa.modules.community.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "社区公告")
public class CommunityAnnouncementController {
    @Autowired
    private CommunityAnnouncementService communityAnnouncementService;
    @ApiOperation("社区公告查询 未读已读分组")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "readState",value =" 0：未读 1：已读 不传就是查询全部",dataType ="string"),

    }
    )
    @GetMapping("/communityAnnouncement/list")
    public Result<List<CommunityAnnouncement>> communityAnnouncementList(@RequestParam @ApiIgnore Map<String,Object> params){
        Result<List<CommunityAnnouncement>> r=Result.success();
        try {
            List<CommunityAnnouncement> communityAnnouncements = this.communityAnnouncementService.querycommunityAnnouncement(params);
            r=Result.success(communityAnnouncements);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }

    @ApiOperation("社区公告查询 (查询后读的状态会变为已读)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "id",value ="查询具体公告的id(必须传)",dataType ="int"),

    }
    )
    @GetMapping("/announcementList/list")
    public Result<List<AnnouncementList>> announcementList(@RequestParam @ApiIgnore Map<String,Object> params){
        Result<List<AnnouncementList>> r=Result.success();
        try {
            List<AnnouncementList> announcementList = this.communityAnnouncementService.announcementList(params);
            r=Result.success(announcementList);
        }catch (Exception e){
            r.setCode("1");
            r.setMsg("error");
            e.printStackTrace();
        }
        return r;
    }
}
